﻿@inherits FilterBase
<Select Items="@Items" @bind-Value="@Value"></Select>

@code {

    private string Value = "true";

    protected override void OnInitialized()
    {
        base.OnInitialized();

        if (TableFilter != null) TableFilter.ShowMoreButton = false;

        Items = new List<SelectedItem>()
        {
            new SelectedItem(){ Value="", Text="全部"},
            new SelectedItem(){ Value="true", Text="是的" },
            new SelectedItem(){ Value="false", Text="不是" }
        };
    }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        await base.OnAfterRenderAsync(firstRender);

        if (firstRender)
        {
            await OnFilterValueChanged();
        }
    }

    public override void Reset()
    {
        Value = "true";

        StateHasChanged();
    }

    public override FilterKeyValueAction GetFilterConditions()
    {
        var filters = new FilterKeyValueAction() { Filters = new() };
        if (!string.IsNullOrEmpty(Value))
        {
            filters.Filters.Add(new FilterKeyValueAction
                {
                    FieldKey = FieldKey,
                    FieldValue = Value,
                    FilterAction = FilterAction.Equal
                });
        }
        return filters;
    }
}
